package Java攻略._2_java_util_function包._1_Consumer接口;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

public class _3_打印集合中的元素 {

    public static void main(String[] args) {

        List<String> stringList = Arrays.asList("this","is","a","list","of","strings");

        // 匿名内部类实现
        stringList.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

        System.out.println("\n");

        // lambda表达式
        stringList.forEach(s -> System.out.println(s));

        System.out.println("\n");

        // 方法引用
        stringList.forEach(System.out::println);
    }
}
